package com.affectu.dao.pagination;

import java.util.List;

import org.hibernate.Session;

import com.affectu.common.util.PersistanceUtil;
import com.affectu.task.InnerTask;
import com.affectu.task.Task;

/**
 * Sep 26, 2008
 * 
 * @author daniel nathan
 */
// @Name("taskListExtendedDataModel")
public class TaskListDataModel extends BaseDataModel<Task, Long> {

    private Session em = PersistanceUtil.getInstance().getSession();

    private static String sql = "select t.* from Tasks t order by t.publishDate desc";

    @Override
    public Task findById(Long id) {
        return (Task) em.get(Task.class, id);
    }

    @Override
    public Long getCount() {
        return Long.valueOf(em.createSQLQuery("select count(t.id) from Tasks t").uniqueResult().toString());
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Task> getList(Integer firstRow, Integer maxResults) {
        return em.createSQLQuery(sql).addEntity("t", InnerTask.class).setFirstResult(firstRow).setMaxResults(maxResults).list();
    }
}
